package edu.ynu.e_platform.dao;

import edu.ynu.e_platform.common.dao.LogicDAO;
import edu.ynu.e_platform.entities.Business;
import edu.ynu.e_platform.entities.Shop;
import edu.ynu.e_platform.entities.ShopItem;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author manwen Yang
 */
@Component
public interface ShopDao extends LogicDAO<Shop, Long> {

    @Query(value = "update Shop s set s.shopImg=:path where s.id=:id")
    @Modifying
    @Transactional
    Integer updateImgById(@Param("path") String path, @Param("id") Long shopId);

    List<Shop> findByBusiness(Business business);

    @Query(value = "select s from Shop s where s.business = :business")
    Page<Shop> find(@Param("business")Business business, Pageable pageable);
}
